What is the result type of the DXL functions before(Object o), after(Object o), and below(Object o)? I want to write following function:
??? getInsertPosition(Object o) {
if (...)
return below(o);
else if (...)
return after(o);
else
return before(o);
}
??? insertPos = getInsertPosition(o);
Object newObj = create(insertPos);
UweR - Tue Jun 30 06:49:12 EDT 2015 |
Re: Result type of before(), after(), below() Hi ! why don't you try something like ...
?? |
Re: Result type of before(), after(), below() Hi The result is of type Object. The best explanation you'll find if you search for "Vertical navigation" Best regards Wolfgang |
Re: Result type of before(), after(), below() What you are trying to do won't work, because before (...), after(...), etc. return different types (which - by the way - you can get from the perms list , that you can download on this forum). Instead you should use a DxlObject or custom struct. Code like this quickly gets complex (when you try to handle the special cases, like create as first object in module, create table cell, etc.). Therefore especially for library code I would recommend a class based approach.
// ************************** enum Position **************************
struct Position {}
Position BEFORE = addr_ 1
Position AFTER = addr_ 2
// stringOf
string gPositionString[] = { "NULL", "before", "after" }
string stringOf (Position p) { return gPositionString[((addr_ p) int)]; }
// *************************** class Position *************************
struct InsertPosition {}
InsertPosition createInsertPosition_ () { DxlObject x = new(); return ((addr_ x) InsertPosition); }
DxlObject DxlObjectOf (InsertPosition this) { return ((addr_ this) DxlObject); }
// property Position
Position getPosition (InsertPosition this) { return ((DxlObjectOf this)->"Position") Position; }
void setPosition(InsertPosition this, Position p) { (DxlObjectOf this)->"Position" = p; }
// property Object
Object getObject(InsertPosition this) { return ((DxlObjectOf this)->"Object") Object; }
void setObject(InsertPosition this, Object p) { (DxlObjectOf this)->"Object" = p; }
// Methods
Object createObject (InsertPosition this) {
Position pos = getPosition this;
if (pos == AFTER) { return create after (getObject this); }
if (pos == BEFORE) { return create before (getObject this); }
error "Invalid position ...";
}
// constructors
InsertPosition createBefore (Object o) { InsertPosition p = createInsertPosition_(); setPosition (p, BEFORE); setObject(p, o); return p; }
InsertPosition createAfter (Object o) { InsertPosition p = createInsertPosition_(); setPosition (p, AFTER); setObject(p, o); return p; }
InsertPosition p1 = createBefore (current);
print "Position p1 is " (stringOf getPosition p1) "\n"
Hope this helps, regards, Mathias
|
Re: Result type of before(), after(), below() Mathias Mamsch - Tue Jun 30 09:06:37 EDT 2015 What you are trying to do won't work, because before (...), after(...), etc. return different types (which - by the way - you can get from the perms list , that you can download on this forum). Instead you should use a DxlObject or custom struct. Code like this quickly gets complex (when you try to handle the special cases, like create as first object in module, create table cell, etc.). Therefore especially for library code I would recommend a class based approach.
// ************************** enum Position **************************
struct Position {}
Position BEFORE = addr_ 1
Position AFTER = addr_ 2
// stringOf
string gPositionString[] = { "NULL", "before", "after" }
string stringOf (Position p) { return gPositionString[((addr_ p) int)]; }
// *************************** class Position *************************
struct InsertPosition {}
InsertPosition createInsertPosition_ () { DxlObject x = new(); return ((addr_ x) InsertPosition); }
DxlObject DxlObjectOf (InsertPosition this) { return ((addr_ this) DxlObject); }
// property Position
Position getPosition (InsertPosition this) { return ((DxlObjectOf this)->"Position") Position; }
void setPosition(InsertPosition this, Position p) { (DxlObjectOf this)->"Position" = p; }
// property Object
Object getObject(InsertPosition this) { return ((DxlObjectOf this)->"Object") Object; }
void setObject(InsertPosition this, Object p) { (DxlObjectOf this)->"Object" = p; }
// Methods
Object createObject (InsertPosition this) {
Position pos = getPosition this;
if (pos == AFTER) { return create after (getObject this); }
if (pos == BEFORE) { return create before (getObject this); }
error "Invalid position ...";
}
// constructors
InsertPosition createBefore (Object o) { InsertPosition p = createInsertPosition_(); setPosition (p, BEFORE); setObject(p, o); return p; }
InsertPosition createAfter (Object o) { InsertPosition p = createInsertPosition_(); setPosition (p, AFTER); setObject(p, o); return p; }
InsertPosition p1 = createBefore (current);
print "Position p1 is " (stringOf getPosition p1) "\n"
Hope this helps, regards, Mathias
Mathias you know, that doxygen has some problems by parsing lines like this? Position BEFORE = addr_ 1 Why don't you use Position BEFORE = addr_(1); ? |
Re: Result type of before(), after(), below() Wolfgang Uhr - Tue Jun 30 12:13:03 EDT 2015 Mathias you know, that doxygen has some problems by parsing lines like this? Position BEFORE = addr_ 1 Why don't you use Position BEFORE = addr_(1); ? Sorry, I wrote that kind of "on-the-fly" and so I did not spend any time on getting that library ready. There is only an example for how you can go about these kind of problems by creating your own structs. |
Re: Result type of before(), after(), below() Less elegant but easier to grasp:
That was scribbling, no attempt to interpret. -Louie You know, I've never notice "before" before. I'm guessing it respects the current display set. I notice "move(o)" has no such "before" option. Curious. |